package study.kits.excel.easyexcel.service.easyexcel.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
public class MyDataListener extends AnalysisEventListener<ExcelImportData> {

    private static final int BATCH_MAX_COUNT = 5;

    private List<ExcelImportData> dataLt = Lists.newArrayList();

    @Override
    public void invoke(ExcelImportData data, AnalysisContext context) {
        log.info(">>>>>> {}", data);
        //
        dataLt.add(data);
        //
        if (dataLt.size() >= BATCH_MAX_COUNT) {
            dataLt.clear();
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        log.info(">>>>>> finish");
        //
        dataLt.clear();
    }
}
